package com.buba.controller;

import com.buba.pojo.Student;
import com.buba.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * Studenr 控制层
 */
@Controller
public class StudentController{
    @Autowired
    StudentService studentService;
    /**
     * 查询所有学生
     * @return
     */
    @RequestMapping("selStudent")
    public String selStudent(Model model){
        List<Student> list = studentService.selStudent();
        model.addAttribute("list",list);
        return "student";
    }

    @RequestMapping("/selStudent")
    public List<Student> selStudent(){
        return studentService.selStudent();
    }

    /**
     * 接收表单参数
     * @return
     */

    @RequestMapping("/addStudent1")

    public String addStudent(int stuId,String stuName,int stuAge,String stuSex,double stuScore){
        System.out.println(stuId);
        System.out.println(stuName);
        System.out.println(stuAge);
        System.out.println(stuSex);
        System.out.println(stuScore);
        return "index.html";
    }

    @RequestMapping("/addStudent2")

    public String addStudent2(Student student){
        System.out.println(student);
        return "index.html";
    }

    /**
     * 使用map集合接收表单参数 需要标注@RequestParam
     * @param map
     * @return
     */
    @RequestMapping("/addStudent3")

    public String addStudent3(@RequestParam Map<String,Object> map){
        System.out.println(map);
        return "index.html";
    }


    /**
     * 使用Servlet原始方式
     * @param request
     * @param session
     * @return
     */

    @RequestMapping("/addStudent4")

    public String addStudent4(HttpServletRequest request, HttpSession session){
        System.out.println();
        return "index.html";
    }
}
